<?php

namespace app\supplier\controller;

use app\supplier\validate\SupplierStoreGoodsAmountValidate;
use app\service\traits\Crud;
use app\supplier\model\SupplierStoreGoodsAmount as SupplierStoreGoodsAmountModel;
use think\Response;
use app\supplier\model\StoreUser;

class SupplierStoreGoodsAmount extends Base
{
    private SupplierStoreGoodsAmountModel $model;

    use Crud;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new SupplierStoreGoodsAmountModel();
        $this->validateClass = SupplierStoreGoodsAmountValidate::class;
        $this->field         = 'id,store_id,goods_id,goods_rule_id,money,original_money,status';
    }


    public function format($list): mixed
    {
        return $list->each(function ($item) {
            $item->store_name        = $item->store()->value('name');
            $storeUser               = StoreUser::storeId($item->store_id)->field('real_name,mobile')->find();
            $item->store_real_name   = $storeUser->real_name;
            $item->store_user_mobile = $storeUser->mobile;
            $item->goods_name        = $item->goods()->value('name');
            $item->goods_spec_name   = $item->goodsRule()->value('spec_name');
        });
    }

    public function addFormat(): array
    {
        return [
            'company_id'  => $this->company_id,
            'supplier_id' => $this->supplier_id
        ];
    }
}